package gu.sql2java.observer;
import static com.google.common.base.Preconditions.checkNotNull;

import gu.sql2java.BaseBean;

public enum TriggerType {
	AFTER_UPDATE,
	AFTER_INSERT,
	AFTER_DELETE,
	BEFORE_UPDATE,
	BEFORE_INSERT,
	BEFORE_DELETE;
	/**
	 * 检查OLD,NEW是否为空,对于不同的 TriggerType,对OLD,NEW要求不同:<br>
	 * INSERT要求NEW不为空<br>
	 * DELETE要求OLD不为空<br>
	 * UPDATE要求NEW,OLD都不为空<br> 
	 * @param _old
	 * @param _new
	 */
	void checkRow(BaseBean _old, BaseBean _new){
		switch(this)
		{
		case AFTER_DELETE:
		case BEFORE_DELETE:
		{
			checkNotNull(_old,"OLD field is null");
			break;
		}
		case AFTER_INSERT:
		case BEFORE_INSERT:
		{
			checkNotNull(_new,"NEW field is null");
			break;
		}
		case AFTER_UPDATE:
		case BEFORE_UPDATE:
		{
			checkNotNull(_new,"NEW field is null");
			checkNotNull(_old,"OLD field is null");
			break;
		}
		}
	}
}
